package me.heshang.rednamedrop.Placeholder;


import me.clip.placeholderapi.PlaceholderAPI;
import me.heshang.rednamedrop.Connection.MySql;
import me.heshang.rednamedrop.Connection.Operation;
import me.heshang.rednamedrop.RedNamedrop;
import org.bukkit.OfflinePlayer;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;

import java.sql.SQLException;


public class Placeholder  extends PlaceholderExpansion {
    private static String byrnd;
    private static String Notrnd;
    public Placeholder(RedNamedrop plugin) {
        super();
    }
    public Placeholder() {}
    @Override
    public String getAuthor() {
        return "RedNamedrop";
    }

    @Override
    public String getIdentifier() {
        return "redname";
    }

    @Override
    public String getVersion() {
        return "1.0";
    }

    @Override
    public boolean persist() {
        return true;
    }

    @Override
    public String onRequest(OfflinePlayer player, String params) {
        if (params.equalsIgnoreCase("currentLevel")) {
            try {
                return String.valueOf(new Operation().querylever(player.getName()));
            } catch (SQLException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
        if (params.equalsIgnoreCase("statusBoolean")) {

            try {
                if (new Operation().querylever(player.getName()) >= 5){
                    return String.valueOf(byrnd);
                }else  return String.valueOf(Notrnd);

            } catch (SQLException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }

        return null;
    }

    public static String getByrnd() {
        return byrnd;
    }

    public static void setByrnd(String byrnd) {
        Placeholder.byrnd = byrnd;
    }

    public static String getNotrnd() {
        return Notrnd;
    }

    public static void setNotrnd(String notrnd) {
        Notrnd = notrnd;
    }
}
